package com.qf.shiro2202day02.utils;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

@Component
public class ApplicationContextUtils implements ApplicationContextAware {

    private static ApplicationContext applicationContext;


    /**
     * springioc容器在创建当前类对象的时候，会调用如下方法，并且把IOC容器对象作为参数传入
     * @param context
     * @throws BeansException
     */
    @Override
    public void setApplicationContext(ApplicationContext context) throws BeansException {
        applicationContext = context;
    }


    public static Object getBean(String name){

        return applicationContext.getBean(name);

    }


    public static <T> T getBean(Class<T> clazz){

        return applicationContext.getBean(clazz);
    }
}
